const {
  $util,
} = getApp();
const MAX_LENGTH = 10;
Page({
  data: {
    list: [],
    page: 1,
    hasMore: true,
    nav: [{ id: 0, title: '待审核' }, { id: 1, title: '已通过' }, { id: 2, title: '未通过' }],
    statustype: 0,
  },
  onLoad(ops) {
    wx.setNavigationBarTitle({
      title: '公益事业',
    });
  },
  onShow() {
    this.setData({
      page: 1,
    }, () => {
      this.loadList();
    });
  },
  onReachBottom() {
    this.data.hasMore && this.loadList();
  },
  changeTab(e) {
    this.setData({
      page: 1,
      statustype: e.detail.obj.id,
    }, () => {
      this.loadList();
    });
  },
  loadList() {
    const {
      page,
      list: d_list,
      statustype,
    } = this.data;
    $util.request({
      url: 'entry/wxapp/partyman.home.getcareer',
      data: {
        page,
        statustype,
      },
      success: (res) => {
        let list = res.data;
        if (page > 1) {
          list = [...d_list, ...list];
        }
        this.setData({
          canshow: res.canshow,
          hasMore: res.data.length === MAX_LENGTH,
          page: res.data.length === MAX_LENGTH ? page + 1 : page,
          list,
        });
      },
    });
  },
});